package Test_1204;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
class cmp implements Comparator<Integer>{
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}

public class Test {
    public static int[] smallestK1(int[] arr, int k) {
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>();
        for (int i = 0; i < arr.length; i++) {
            priorityQueue.offer(arr[i]);
        }
        int[] ret=new int[k];
        for (int i = 0; i < k; i++) {
            ret[i]=priorityQueue.poll();
        }
        return ret;
    }
    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>();
        int[] a={1,5,13,2};
        int k=2;
        smallestK1(a,k);
        //插入元素
        priorityQueue.offer(24);
        priorityQueue.offer(12);
        priorityQueue.offer(35);
        priorityQueue.offer(20);
        //获取优先级最高的元素
        priorityQueue.peek();
        //删除指定元素
        priorityQueue.remove(35);
        //删除优先级最高的元素
        priorityQueue.poll();
        //.....
    }
    public static void main1(String[] args) {
        int[] array={15,28,17,36,45,23,35,56};
        Heap heap=new Heap();
        heap.initHeap(array);
        heap.creatHeap1();
        for (int i = 0; i < heap.elem.length; i++) {
            System.out.print(heap.elem[i]+" ");
        }
        System.out.println();
        heap.creatHeap2();
        for (int i = 0; i < heap.elem.length; i++) {
            System.out.print(heap.elem[i]+" ");
        }
    }
}
